/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package giuliani_mapelli_marocco.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "weatherforecast")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Weatherforecast.findAll", query = "SELECT w FROM Weatherforecast w"),
    @NamedQuery(name = "Weatherforecast.findByDate", query = "SELECT w FROM Weatherforecast w WHERE w.weatherforecastPK.date = :date"),
    @NamedQuery(name = "Weatherforecast.findByPlace", query = "SELECT w FROM Weatherforecast w WHERE w.weatherforecastPK.place = :place"),
    @NamedQuery(name = "Weatherforecast.findByWeather", query = "SELECT w FROM Weatherforecast w WHERE w.weather = :weather"),
    @NamedQuery(name = "Weatherforecast.findByTempMin", query = "SELECT w FROM Weatherforecast w WHERE w.tempMin = :tempMin"),
    @NamedQuery(name = "Weatherforecast.findByTempMax", query = "SELECT w FROM Weatherforecast w WHERE w.tempMax = :tempMax"),
    @NamedQuery(name = "Weatherforecast.findByHumidity", query = "SELECT w FROM Weatherforecast w WHERE w.humidity = :humidity"),
    @NamedQuery(name= "Weatherforecast.findByDateAndPlace", query = "SELECT w FROM Weatherforecast w WHERE (w.weatherforecastPK.date = :date AND w.weatherforecastPK.place = :place)")})
public class Weatherforecast implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected WeatherforecastPK weatherforecastPK;
   
    @NotNull
    private int weather;
   
    @NotNull
    private float tempMin;
  
    @NotNull
    private float tempMax;

    @NotNull
    private int humidity;
    
    @JoinTable(name = "eventweather", joinColumns = {
        @JoinColumn(name = "date", referencedColumnName = "date"),
        @JoinColumn(name = "place", referencedColumnName = "place")}, inverseJoinColumns = {
        @JoinColumn(name = "idEvent", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Event> eventCollection;

    public Weatherforecast() {
    }

    public Weatherforecast(WeatherforecastPK weatherforecastPK) {
        this.weatherforecastPK = weatherforecastPK;
    }

    public Weatherforecast(WeatherforecastPK weatherforecastPK, int weather, float tempMin, float tempMax, int humidity) {
        this.weatherforecastPK = weatherforecastPK;
        this.weather = weather;
        this.tempMin = tempMin;
        this.tempMax = tempMax;
        this.humidity = humidity;
    }

    public Weatherforecast(Date date, String place) {
        this.weatherforecastPK = new WeatherforecastPK(date, place);
    }

    public WeatherforecastPK getWeatherforecastPK() {
        return weatherforecastPK;
    }

    public void setWeatherforecastPK(WeatherforecastPK weatherforecastPK) {
        this.weatherforecastPK = weatherforecastPK;
    }

    public int getWeather() {
        return weather;
    }

    public void setWeather(int weather) {
        this.weather = weather;
    }

    public float getTempMin() {
        return tempMin;
    }

    public void setTempMin(float tempMin) {
        this.tempMin = tempMin;
    }

    public float getTempMax() {
        return tempMax;
    }

    public void setTempMax(float tempMax) {
        this.tempMax = tempMax;
    }

    public int getHumidity() {
        return humidity;
    }

    public void setHumidity(int humidity) {
        this.humidity = humidity;
    }

    @XmlTransient
    public Collection<Event> getEventCollection() {
        return eventCollection;
    }

    public void setEventCollection(Collection<Event> eventCollection) {
        this.eventCollection = eventCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (weatherforecastPK != null ? weatherforecastPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Weatherforecast)) {
            return false;
        }
        Weatherforecast other = (Weatherforecast) object;
        if ((this.weatherforecastPK == null && other.weatherforecastPK != null) || (this.weatherforecastPK != null && !this.weatherforecastPK.equals(other.weatherforecastPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "giuliani_mapelli_marocco.entity.Weatherforecast[ weatherforecastPK=" + weatherforecastPK + " ]";
    }
    
}
